package com.tool_stdy.utils.guava;

import java.util.HashMap;
import java.util.Map.Entry;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multiset;

public class MutilTest {

    /**
     * 统计单词个数
     * HashMultiset 允许重复
     */
    public static void MutilSetTest() {
        String src = "this is a cat that is a dog where is it";
        String[] split = src.split(" ");
        HashMultiset<String> create = HashMultiset.create();
        for (String srcs : split) {
            create.add(srcs);
        }
        for (String srcs : split) {
            System.out.println(srcs + "--->" + create.count(srcs));
        }
    }

    /**
     * Multimap key允许重复 
     * 所以get(key)为一个集合
     */
    public static void MulitHashTest() {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("数学", "张老师");
        map.put("语文", "李老师");
        map.put("体育", "王老师");
        map.put("计算机", "张老师");
        map.put("美术", "张老师");

        Multimap<String, String> create = ArrayListMultimap.create();
        for (Entry<String, String> en : map.entrySet()) {
            create.put(en.getValue(), en.getKey());
        }
        Multiset<String> keys = create.keys();
        for (String key : keys.elementSet()) {
            System.out.println(key + "--->" + create.get(key));
        }
    }

    public static void main(String[] args) {
        //MutilSetTest();
        MulitHashTest();
    }
}
